package com.edu.exam.enums.core;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 教室类型枚举
 */
public enum RoomType implements BaseEnum {
    LECTURE_HALL("LECTURE_HALL", "阶梯教室"),
    CLASSROOM("CLASSROOM", "普通教室"),
    LABORATORY("LABORATORY", "实验室"),
    COMPUTER_LAB("COMPUTER_LAB", "计算机实验室"),
    CONFERENCE_ROOM("CONFERENCE_ROOM", "会议室"),
    MULTIMEDIA_ROOM("MULTIMEDIA_ROOM", "多媒体教室"),
    STUDIO("STUDIO", "工作室"),
    LIBRARY("LIBRARY", "图书馆"),
    GYMNASIUM("GYMNASIUM", "体育馆"),
    AUDITORIUM("AUDITORIUM", "报告厅"),
    SEMINAR_ROOM("SEMINAR_ROOM", "研讨室"),
    DRAWING_ROOM("DRAWING_ROOM", "绘图室"),
    MUSIC_ROOM("MUSIC_ROOM", "音乐教室"),
    ART_ROOM("ART_ROOM", "美术教室"),
    LANGUAGE_LAB("LANGUAGE_LAB", "语言实验室"),
    PHYSICS_LAB("PHYSICS_LAB", "物理实验室"),
    CHEMISTRY_LAB("CHEMISTRY_LAB", "化学实验室"),
    BIOLOGY_LAB("BIOLOGY_LAB", "生物实验室"),
    WORKSHOP("WORKSHOP", "实训车间"),
    OTHER("OTHER", "其他");

    private final String code;
    private final String description;

    RoomType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static RoomType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Room type code cannot be null or empty");
        }

        for (RoomType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown RoomType code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static RoomType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Room type description cannot be null or empty");
        }

        for (RoomType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown RoomType description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}